package com.coldwindblows.blog.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.coldwindblows.blog.pojo.MetaDo;

/**
 * 后台公共函数
 * Created by ColdWindBlows on 2018/07/07
 */
@Component
public class AdminCommons {

	private static final String[] COLORS = {"default", "primary", "success", "info", "warning", "danger", "inverse", "purple", "pink"};
	
	/**
	 * 判断category和cat是否有交集
	 * @param category
	 * @param cats
	 * @return
	 */
	public static boolean exist_cat(MetaDo category, String cats) {
		String[] arr = StringUtils.split(cats, ",");
		if(arr == null || arr.length <= 0) {
			return false;
		}
		
		for(String str : arr) {
			if(str.trim().equals(category.getName())) {
				return true;
			}
		}
		
		return false;
	}
	
	public static String rand_color() {
		int r = Tools.rand(0, COLORS.length -1);
		return COLORS[r];
	}
}
